package com.julius.design.pattern.prototype;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *      缓存
 * </p>
 */
public class PrototypeCache {

    private static final Map<String,Shape> SHAPE_MAP;

    static {
        HashMap<String,Shape> map = new HashMap<>();
        Circle circle = new Circle();
        circle.setId("circle");
        map.put(circle.getId(),circle);

        Square square = new Square();
        square.setId("square");
        map.put(square.getId(),square);
        SHAPE_MAP = Collections.unmodifiableMap(map);
    }

    public Shape getShape(String id) throws CloneNotSupportedException {
        return (Shape) SHAPE_MAP.get(id).clone();
    }



}
